Skip to content

fix(cli): use ditto instead of fs::copy to preserve macOS code signing#113

Open
DorianZheng wants to merge 1 commit intomainfrom
fix/cli-macos-copy-metadata
Open

fix(cli): use ditto instead of fs::copy to preserve macOS code signing#113
DorianZheng wants to merge 1 commit intomainfrom
fix/cli-macos-copy-metadata

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

Summary

  • Replace Rust's fs::copy() with macOS ditto command in build.rs to preserve code signing metadata when copying runtime files
  • Use cp -R -T on Linux for similar behavior

Problem

CLI and shim binaries were killed with SIGKILL (exit 137) on macOS because fs::copy() creates new files that lose code signing extended attributes, causing "Invalid Page" code signature validation failures at dyld load time.

The crash report showed:

"signal":"SIGKILL (Code Signature Invalid)"
"termination":{"namespace":"CODESIGNING","indicator":"Invalid Page"}

Root Cause

  • fs::copy() creates a new file that doesn't preserve macOS code signing metadata
  • When binaries are copied from target/boxlite-runtime/ to ~/.local/share/boxlite/, the code signatures become invalid
  • macOS kills the process at dyld load time before any code executes

Solution

Use ditto on macOS which preserves extended attributes, resource forks, and code signing metadata.

Test plan

  • Clean rebuild: rm -rf ~/.local/share/boxlite && make cli
  • Test CLI: ./target/debug/boxlite -h shows help
  • Test shim: ~/.local/share/boxlite/boxlite-shim --help shows help

@DorianZheng
Copy link
Copy Markdown
Member Author

@shayne-snap Hi, I found a bug when use rust std::fs::copy didn't preserve signing. Would you like to review?

Replace Rust's fs::copy() with macOS ditto command in build.rs to
preserve code signing metadata when copying runtime files.

Problem: CLI and shim binaries were killed with SIGKILL (exit 137)
on macOS because fs::copy() creates new files that lose code signing
extended attributes, causing "Invalid Page" code signature validation
failures at dyld load time.

Solution: Use ditto on macOS which preserves extended attributes,
resource forks, and code signing metadata. Use cp -R -T on Linux.
@DorianZheng DorianZheng force-pushed the fix/cli-macos-copy-metadata branch from 886a8ed to eccbc7b Compare January 13, 2026 08:51
@shayne-snap
Copy link
Copy Markdown
Contributor

Hi @DorianZheng I haven't came across this problem on my laptop(Apple chip M2). Which platform are you on?

bcz I'm using runtime-debug?

cli: runtime-debug

@DorianZheng
Copy link
Copy Markdown
Member Author

Hi @DorianZheng I haven't came across this problem on my laptop(Apple chip M2). Which platform are you on?

bcz I'm using runtime-debug?

cli: runtime-debug

Hi, my mac chip is Apple M1 Pro. I think maybe it's the cache thing. Can you try make clean and make cli?

@shayne-snap
Copy link
Copy Markdown
Contributor

After executing make clean and make cli on different branches (twice), both version work on my laptop(./target/debug/boxlite -h works).

@shayne-snap
Copy link
Copy Markdown
Contributor

LGTM

@DorianZheng
Copy link
Copy Markdown
Member Author

After executing make clean and make cli on different branches (twice), both version work on my laptop(./target/debug/boxlite -h works).

@shayne-snap Ahhh, that's weird. I will paste the reproduce steps here in some time. Before that, I will leave this PR open and won't merge it.

@uran0sH
Copy link
Copy Markdown
Contributor

uran0sH commented Jan 13, 2026

I test on M2 chip and macOS Sequoia. It also works for me.

@shayne-snap
Copy link
Copy Markdown
Contributor

shayne-snap commented Jan 29, 2026

After executing make clean and make cli on different branches (twice), both version work on my laptop(./target/debug/boxlite -h works).

@shayne-snap Ahhh, that's weird. I will paste the reproduce steps here in some time. Before that, I will leave this PR open and won't merge it.

I came across the same problem on my laptop after I created two dirs inboxlite-cliand move some files into the dirs. Don't know why make clean doesn't work.

@shayne-snap
Copy link
Copy Markdown
Contributor

This PR works for me. Could you merge it into main? @DorianZheng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants